package com.huluobo.a2203kotlinshopping.register

import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.huluobo.base.bean.UserBeanResult
import com.huluobo.base.net.Const
import com.huluobo.base.viewModel.BaseViewModel
import okhttp3.MediaType
import okhttp3.RequestBody

/**
 *  Created by LC on 2024/6/24.
 */
class RegisterViewModel : BaseViewModel<RegisterRepo>() {

    val registerSuccess = MutableLiveData<UserBeanResult>()
    val registerFailed = MutableLiveData<String>()

    fun register(username: String, password: String, rePassword: String) {
        val map = mutableMapOf<String, String>()
        map[Const.PARAM_USERNAME] = username
        map[Const.PARAM_PASSWORD] = password
        map[Const.PARAM_RE_PASSWORD] = rePassword
        val json = Gson().toJson(map)
        val body = RequestBody.create(MediaType.parse(Const.MEDIA_TYPE), json)
        repo.register(body, registerSuccess, registerFailed)
    }

    override fun createRepo(): RegisterRepo = RegisterRepo()
}